package online.longzipeng.cinemasys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import online.longzipeng.cinemasys.entity.WebConfig;
import online.longzipeng.cinemasys.mapper.WebConfigMapper;
import online.longzipeng.cinemasys.service.WebConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import online.longzipeng.cinemasys.vo.webconfig.WebConfigUpdateVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lzp
 * @since 2021-05-13
 */
@Service
public class WebConfigServiceImpl extends ServiceImpl<WebConfigMapper, WebConfig> implements WebConfigService {

    @Override
    public String getByKey(String name) {
        QueryWrapper<WebConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name",name);
        WebConfig one = getOne(queryWrapper);
        return one.getValue();
    }

    @Override
    public void updateByKey(WebConfigUpdateVO webConfigUpdateVO) {
        QueryWrapper<WebConfig> qwWebConfig = new QueryWrapper<>();
        qwWebConfig.eq("name",webConfigUpdateVO.getName());
        WebConfig webConfig = new WebConfig();
        BeanUtils.copyProperties(webConfigUpdateVO,webConfig);
        update(webConfig,qwWebConfig);
    }
}
